package com.chaosj.tools.stocks

import com.chaosj.tools.StockDiscoverTools
import com.chaosj.tools.rules.BaseUpDownRule
import com.chaosj.tools.rules.CombinationRule
import com.chaosj.tools.rules.DownRule
import com.chaosj.tools.rules.FiveUpRule
import com.chaosj.tools.rules.LastDayDownButBldUpRule
import com.chaosj.tools.rules.LimitRule
import com.chaosj.tools.rules.SpanRule
import com.chaosj.tools.rules.UpRule3
import com.chaosj.tools.rules.YesterdayMaxAndTodayUp

import java.nio.file.Files
import java.nio.file.Path
import java.time.LocalDate

class ExtractStocks {
//    static String basePath = "G:\\platform\\hot-project-git\\spring-stack-skills\\skill-tools\\src\\main\\resources\\"
    static String basePath = "E:\\platform\\github\\spring-stack-skills\\skill-tools\\src\\main\\resources\\"
    static void main(args){
        CombinationRule.getInstance().registerRule(
            // 昨日下跌,今天竞价上涨 规则
            new LastDayDownButBldUpRule(),
            // 昨天涨停,今天竞价超过 5个点
            new YesterdayMaxAndTodayUp(),
            // 前天涨停,昨天大涨后回调,今天抢筹
            new UpRule3(),
            // 昨天大涨9个点以上,并且尾盘下跌3个点。今天开盘竞价在-2个点以内
            new DownRule(),
            // 涨停后连续大跌
            new LimitRule(),
            // 前天涨停,昨天震荡超过15个点,今天低开3个点以内
            new SpanRule(),
            // 连续3天红盘或者绿盘
//            new BaseUpDownRule(),
            // 连续5天红盘或者绿盘
            new FiveUpRule()
        )
        StockDiscoverTools.requestStockInfo(getStocks().values().asList(),basePath)
        StockDiscoverTools.analysisStocks(getStocks().keySet().toList(),basePath)
    }

    static Map<String,String> getStocks(){
        Map<String,String> data = new HashMap<>()
        int val = LocalDate.now().getDayOfWeek().value
        String dateStr = val== 6 ? LocalDate.now().minusDays(1).toString() : val == 7 ? LocalDate.now().minusDays(2).toString() : LocalDate.now().toString()
        Path path = new File(basePath+dateStr+".stock").toPath()
        Files.readAllLines(path).stream().forEach({value->
            String[] values = value.split("\\#")
            data.put(values[0],values[1])
        })
        return data
    }
}
